/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;

init(config: OpenApi.Config){
  super(config);
  @endpointRule = '';
  

  checkConfig(config);
  @endpoint = getEndpoint('cmpinc', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }

  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}
model CreateOXSDeliveryTaskRequest {
  azoneId?: string(name='AzoneId'),
  deliveryApp?: string(name='DeliveryApp'),
  deliveryProduct?: string(name='DeliveryProduct'),
  domestic?: boolean(name='Domestic'),
  empIds?: [ string ](name='EmpIds'),
  idcName?: string(name='IdcName'),
  idcNameForExpansion?: string(name='IdcNameForExpansion'),
  instanceType?: string(name='InstanceType'),
  ipCidrBlocks?: [ string ](name='IpCidrBlocks'),
  isDisabled?: boolean(name='IsDisabled'),
  latitude?: float(name='Latitude'),
  longitude?: float(name='Longitude'),
  regionId?: string(name='RegionId'),
  regionName?: string(name='RegionName'),
  securityGroupType?: string(name='SecurityGroupType'),
  skipCreateEcs?: boolean(name='SkipCreateEcs'),
  skipQuotaApply?: boolean(name='SkipQuotaApply'),
  supportVpc?: boolean(name='SupportVpc'),
  systemDiskCategory?: string(name='SystemDiskCategory'),
  zoneId?: string(name='ZoneId'),
}

model CreateOXSDeliveryTaskResponseBody = {
  requestId?: string(name='RequestId'),
  taskId?: long(name='TaskId'),
}

model CreateOXSDeliveryTaskResponse = {
  headers: map[string]string(name='headers'),
  body: CreateOXSDeliveryTaskResponseBody(name='body'),
}

async function createOXSDeliveryTaskWithOptions(request: CreateOXSDeliveryTaskRequest, runtime: Util.RuntimeOptions): CreateOXSDeliveryTaskResponse {
  Util.validateModel(request);
  var query = {};
  query["AzoneId"] = request.azoneId;
  query["DeliveryApp"] = request.deliveryApp;
  query["DeliveryProduct"] = request.deliveryProduct;
  query["Domestic"] = request.domestic;
  query["EmpIds"] = request.empIds;
  query["IdcName"] = request.idcName;
  query["IdcNameForExpansion"] = request.idcNameForExpansion;
  query["InstanceType"] = request.instanceType;
  query["IpCidrBlocks"] = request.ipCidrBlocks;
  query["IsDisabled"] = request.isDisabled;
  query["Latitude"] = request.latitude;
  query["Longitude"] = request.longitude;
  query["RegionId"] = request.regionId;
  query["RegionName"] = request.regionName;
  query["SecurityGroupType"] = request.securityGroupType;
  query["SkipCreateEcs"] = request.skipCreateEcs;
  query["SkipQuotaApply"] = request.skipQuotaApply;
  query["SupportVpc"] = request.supportVpc;
  query["SystemDiskCategory"] = request.systemDiskCategory;
  query["ZoneId"] = request.zoneId;
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
    body = Util.toMap(request),
  };
  var params = new OpenApi.Params{
    action = 'CreateOXSDeliveryTask',
    version = '2021-01-13',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function createOXSDeliveryTask(request: CreateOXSDeliveryTaskRequest): CreateOXSDeliveryTaskResponse {
  var runtime = new Util.RuntimeOptions{};
  return createOXSDeliveryTaskWithOptions(request, runtime);
}

model DeleteOXSDeliveryWhiteListRequest {
  idcName?: string(name='IdcName'),
  taskId?: long(name='TaskId'),
}

model DeleteOXSDeliveryWhiteListResponseBody = {
  requestId?: string(name='RequestId'),
}

model DeleteOXSDeliveryWhiteListResponse = {
  headers: map[string]string(name='headers'),
  body: DeleteOXSDeliveryWhiteListResponseBody(name='body'),
}

async function deleteOXSDeliveryWhiteListWithOptions(request: DeleteOXSDeliveryWhiteListRequest, runtime: Util.RuntimeOptions): DeleteOXSDeliveryWhiteListResponse {
  Util.validateModel(request);
  var query = {};
  query["IdcName"] = request.idcName;
  query["TaskId"] = request.taskId;
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
    body = Util.toMap(request),
  };
  var params = new OpenApi.Params{
    action = 'DeleteOXSDeliveryWhiteList',
    version = '2021-01-13',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function deleteOXSDeliveryWhiteList(request: DeleteOXSDeliveryWhiteListRequest): DeleteOXSDeliveryWhiteListResponse {
  var runtime = new Util.RuntimeOptions{};
  return deleteOXSDeliveryWhiteListWithOptions(request, runtime);
}

model GetTaskRequest {
  clientToken?: string(name='ClientToken'),
  taskId?: long(name='TaskId'),
}

model GetTaskResponseBody = {
  appName?: string(name='AppName'),
  bpmsUrl?: string(name='BpmsUrl'),
  completeTime?: string(name='CompleteTime'),
  createTime?: string(name='CreateTime'),
  details?: [ 
    {
      data?: map[string]any(name='Data'),
      resourceId?: string(name='ResourceId'),
      resourceType?: string(name='ResourceType'),
    }
  ](name='Details'),
  requestId?: string(name='RequestId'),
  status?: string(name='Status'),
  statusReason?: string(name='StatusReason'),
  taskId?: long(name='TaskId'),
  taskType?: string(name='TaskType'),
}

model GetTaskResponse = {
  headers: map[string]string(name='headers'),
  body: GetTaskResponseBody(name='body'),
}

async function getTaskWithOptions(request: GetTaskRequest, runtime: Util.RuntimeOptions): GetTaskResponse {
  Util.validateModel(request);
  var query = {};
  query["ClientToken"] = request.clientToken;
  query["TaskId"] = request.taskId;
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
    body = Util.toMap(request),
  };
  var params = new OpenApi.Params{
    action = 'GetTask',
    version = '2021-01-13',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function getTask(request: GetTaskRequest): GetTaskResponse {
  var runtime = new Util.RuntimeOptions{};
  return getTaskWithOptions(request, runtime);
}

model ListTasksRequest {
  appName?: map[string]any(name='AppName'),
  maxResults?: long(name='MaxResults'),
  nextToken?: string(name='NextToken'),
  status?: string(name='Status'),
  taskType?: string(name='TaskType'),
}

model ListTasksShrinkRequest {
  appNameShrink?: string(name='AppName'),
  maxResults?: long(name='MaxResults'),
  nextToken?: string(name='NextToken'),
  status?: string(name='Status'),
  taskType?: string(name='TaskType'),
}

model ListTasksResponseBody = {
  nextToken?: string(name='NextToken'),
  requestId?: string(name='RequestId'),
  tasks?: [ 
    {
      appName?: string(name='AppName'),
      bpmsUrl?: string(name='BpmsUrl'),
      completeTime?: string(name='CompleteTime'),
      createTime?: string(name='CreateTime'),
      status?: string(name='Status'),
      statusReason?: string(name='StatusReason'),
      taskId?: long(name='TaskId'),
      taskType?: string(name='TaskType'),
    }
  ](name='Tasks'),
}

model ListTasksResponse = {
  headers: map[string]string(name='headers'),
  body: ListTasksResponseBody(name='body'),
}

async function listTasksWithOptions(tmpReq: ListTasksRequest, runtime: Util.RuntimeOptions): ListTasksResponse {
  Util.validateModel(tmpReq);
  var request = new ListTasksShrinkRequest{};
  OpenApiUtil.convert(tmpReq, request);
  if (!Util.isUnset(tmpReq.appName)) {
    request.appNameShrink = OpenApiUtil.arrayToStringWithSpecifiedStyle(tmpReq.appName, 'AppName', 'json');
  }
  var query = {};
  query["AppName"] = request.appNameShrink;
  query["MaxResults"] = request.maxResults;
  query["NextToken"] = request.nextToken;
  query["Status"] = request.status;
  query["TaskType"] = request.taskType;
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
    body = Util.toMap(request),
  };
  var params = new OpenApi.Params{
    action = 'ListTasks',
    version = '2021-01-13',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function listTasks(request: ListTasksRequest): ListTasksResponse {
  var runtime = new Util.RuntimeOptions{};
  return listTasksWithOptions(request, runtime);
}

